import os
import fnmatch
import glob
from typing import List, Dict, Callable
def walk(
    app_path: str,
    callback: Callable[[str, str], List[Dict]],
    include_list: List[str],
    ignore_list: List[str] = []
) -> List[Dict]:
    
    all_files = set()
    for pattern in include_list:
        if "**" in pattern:
            all_files.update(glob.glob(
                os.path.join(app_path, pattern),
                recursive=True
            ))
        else:
            for root, _, files in os.walk(app_path):
                for file in files:
                    path = os.path.join(root, file).replace(os.sep, '/')
                    if fnmatch.fnmatch(path, os.path.join(app_path, pattern).replace(os.sep, '/')):
                        all_files.add(path)
    
    # 过滤黑名单
    permissions = []
    for file_path in all_files:
        if any(fnmatch.fnmatch(file_path, p) for p in ignore_list):
            continue
        
        # 解析控制器
        rel_path = os.path.relpath(os.path.dirname(file_path), app_path)
        app_name = rel_path.split(os.sep)[0]
        permissions.extend(callback(file_path, app_name))
    
    return permissions
